#include "includes_fw.h"
#include "config_fw.h"
#include "hdm_ctl.h"
#include "lib_retina.h"

#if SUPPORT_FLASH_LIGHT

#if BIND_FLASH_TPS61050

void FLASH_TPS61050_TorchModeOn(MMP_UBYTE level);
void FLASH_TPS61050_TorchModeOff(void);

void FLASH_TPS61050_Init(void)
{
	MMP_USHORT read_value;

    //VR_FLASH_ConfigI2C(0x33, ISP_I2C_TYPE_1A1D);
    //MMPF_OS_Sleep(1);

    MMPF_FLASH_ReadI2C(0x00, &read_value);  //  should be 0x12.
    RTNA_DBG_Str(3, " Read TPS61050 Reg[0x00] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
    MMPF_FLASH_ReadI2C(0x01, &read_value);  //  should be 0x04.
    RTNA_DBG_Str(3, " Read TPS61050 Reg[0x01] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
    MMPF_FLASH_ReadI2C(0x02, &read_value);  //  should be 0x00.
    RTNA_DBG_Str(3, " Read TPS61050 Reg[0x02] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
    MMPF_FLASH_ReadI2C(0x03, &read_value);  //  should be 0xD1.
    RTNA_DBG_Str(3, " Read TPS61050 Reg[0x03] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  

    FLASH_TPS61050_TorchModeOn(1);
    MMPF_FLASH_ReadI2C(0x00, &read_value);  //  should be 0x50.
    RTNA_DBG_Str(3, " Read TPS61050 Reg[0x00] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
    MMPF_OS_Sleep(200);
    FLASH_TPS61050_TorchModeOff();
    MMPF_FLASH_ReadI2C(0x00, &read_value);  //  should be 0x50.
    RTNA_DBG_Str(3, " Read TPS61050 Reg[0x00] = ");       
    RTNA_DBG_Short(3, read_value);  
    RTNA_DBG_Str(3, "\r\n");  
    

}

void FLASH_TPS61050_FlashModeOn(MMP_UBYTE level)
{
    RTNA_DBG_Str(3, "FLASH_TPS61050_FlashModeOn().....\r\n");  
    MMPF_FLASH_WriteI2C(0x01, 0x8C);  // [7:6]: 10->Device operates in torch and flash modes, [3]: Start flash/Timer
}

void FLASH_TPS61050_FlashModeOff(void)
{
    RTNA_DBG_Str(3, "FLASH_TPS61050_FlashModeOff().....\r\n");  
    MMPF_FLASH_WriteI2C(0x01, 0x04);  // [7:6]: 
}

void FLASH_TPS61050_TorchModeOn(MMP_UBYTE level)
{
    RTNA_DBG_Str(3, "FLASH_TPS61050_TorchModeOn().....\r\n");  
    MMPF_FLASH_WriteI2C(0x00, 0x52);  // [7:6]: 10->Device operates in torch and flash modes, [3]: Start flash/Timer
}

void FLASH_TPS61050_TorchModeOff(void)
{
    RTNA_DBG_Str(3, "FLASH_TPS61050_TorchModeOff().....\r\n");  
    MMPF_FLASH_WriteI2C(0x00, 0x12);  // [7:6]: 10->Device operates in torch and flash modes, [3]: Start flash/Timer
}

#endif

#endif
